#include <iostream>
#include <cstdlib>
#define MAX_BOX 30
#define MAX_DIMENSION 10

using namespace std;

struct Box {
	int no;
	int edge[MAX_DIMENSION];
	int dimension;
	bool operator<(Box &other);
};

bool Box::operator<(Box &other) {
	for(int i = 0; i < dimension; ++i)
		if( !(edge[i] < other.edge[i]) )
				return false;
	return true;
}

void IncreasingSort(int[], int);
bool box_less(const Box&, const Box&, int);

int main(void) {
	Box box[30];
	int num_box, dimension;
	int length[MAX_BOX];
	int prev[MAX_BOX];

	while (cin >> num_box >> dimension) {
		for (int i = 0; i < num_box; ++i) {
			box[i].no = i + 1;
			box[i].dimension = dimension;
			for (int j = 0; j < dimension; ++j)
				cin >> box[i].edge[j];
			IncreasingSort(box[i].edge, dimension);
			length[i] = 1;
			prev[i] = -1;
		}
		//box compare
		for (int order_times = 0, i = num_box - 1; (i > 0) && (num_box != order_times); --i, ++order_times) {
			for (int j = 0; j != i; ++j) {
				if (box[i] < box[j]) {
					Box temp;
					temp = box[i];
					for (int k = i; k > j; --k)
						box[k] = box[k - 1];
					box[j] = temp;
					++i;
					break;
				}
			}
		}
		for (int i = 0; i < num_box; ++i) {
			for (int j = i + 1; j < num_box; ++j) {
				if (box[i] < box[j]) {
					if (length[i] + 1 > length[j]) {
						length[j] = length[i] + 1;
						prev[j] = i;
					}
				}
			}
		}
		//find the max length of the all boxes
		int max_length = length[0];
		int max = 0;
		for (int i = 1; i < num_box; ++i) {
			if (max_length < length[i])
				max = i;
		}

		//print the result
		cout << length[max] << endl;

		int output_seq[MAX_BOX];
		int size = 0;

		int cur = max;
		do {
			output_seq[size++] = box[cur].no;
			cur = prev[cur];
		} while (cur != -1);

		for (int i = size - 1; i > 0; --i)
			cout << output_seq[i] << " ";
		cout << output_seq[0] << endl;
	}

#ifndef ONLINE_JUDGE
	system("pause");
#endif

	return 0;
}

void IncreasingSort(int edge[], int dimension) {
	int temp;
	for (int i = 0; i < dimension; ++i) {
		for (int j = 0; j < (dimension - i - 1); ++j) {
			if (edge[j] > edge[j + 1]) {
				temp = edge[j];
				edge[j] = edge[j + 1];
				edge[j + 1] = temp;
			}
		}
	}
}